
public class list {
	
		public element head = new element();
		
		public void add_end(element elem){
			if(head.next == head){
				head.next=elem;
				head.prev=elem;
				elem.next=head;
				elem.prev=head;
			}else{
				element cur = head;
				while(cur.next!=head){
					cur = cur.next;
				}
				cur.next = elem;
				elem.prev = cur;
				elem.next = head;
				head.prev = elem;
			}
		}
		public void add_begin(element elem){
			if(head.next == head){
				head.next=elem;
				head.prev=elem;
				elem.next=head;
				elem.prev=head;
			}else{
				element cur = head.next;
				head.next = elem;
				elem.prev = head;
				elem.next = cur;
				cur.prev = elem;
			}
		}
		public String toString(){
			StringBuffer sb = new StringBuffer();
			sb.append("[ ");
			element current = head.next;
			while (current != head){
				sb.append(current.i + " ");
				current = current.next;
			}
			sb.append("]");
			return sb.toString();
		}
	}
